home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet internetowy / Przegladarki internetowe / Mozilla Seamonkey 1.0.5 pl / seamonkey-1.0.5.pl-PL.win32.installer.exe / BROWSER.XPI / bin / chrome / toolkit.jar / content / global / consoleBindings.xml < prev    next >
Encoding:
Extensible Markup Language  |  2005-04-15  |  13.7 KB  |  391 lines

  1. <?xml version="1.0"?>
  2.  
  3. <!DOCTYPE window SYSTEM "chrome://global/locale/console.dtd">
  4.  
  5. <bindings id="consoleBindings"
  6.           xmlns="http://www.mozilla.org/xbl"
  7.           xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  8.           xmlns:xbl="http://www.mozilla.org/xbl">
  9.  
  10.   <binding id="console-box" extends="xul:box">
  11.     <content>  
  12.       <xul:stringbundle src="chrome://global/locale/console.properties" role="string-bundle"/>
  13.       <xul:vbox class="console-box-internal">
  14.         <xul:vbox class="console-rows" role="console-rows" xbl:inherits="dir=sortOrder"/>
  15.       </xul:vbox>
  16.     </content>
  17.   
  18.     <implementation implements="nsIConsoleListener">
  19.       <field name="limit" readonly="true">
  20.         250
  21.       </field>
  22.       <field name="_showChromeErrors">-1</field>
  23.       
  24.       <property name="showChromeErrors">
  25.         <getter><![CDATA[
  26.           if (this._showChromeErrors != -1)
  27.             return this._showChromeErrors;
  28.           var pref = Components.classes['@mozilla.org/preferences-service;1'].getService();
  29.           pref = pref.QueryInterface(Components.interfaces.nsIPrefBranch);
  30.  
  31.           try {
  32.             return this._showChromeErrors = pref.getBoolPref("javascript.options.showInConsole");
  33.           }
  34.           catch(ex) {
  35.             return this._showChromeErrors = false;
  36.           }
  37.         ]]></getter>
  38.       </property>          
  39.  
  40.       <property name="count" readonly="true">
  41.         <getter>return this.mCount</getter>
  42.       </property>
  43.     
  44.       <property name="mode">
  45.         <getter>return this.mMode;</getter>
  46.         <setter><![CDATA[
  47.           this.mMode = val || "All";
  48.           this.setAttribute("mode", this.mMode);
  49.           return val;
  50.         ]]></setter>
  51.       </property>
  52.     
  53.       <property name="sortOrder">
  54.         <getter>return this.getAttribute("sortOrder");</getter>
  55.         <setter>this.setAttribute("sortOrder", val); return val;</setter>
  56.       </property>
  57.       <field name="mSelectedItem">null</field>
  58.       <property name="selectedItem">
  59.         <getter>return this.mSelectedItem</getter>
  60.         <setter><![CDATA[
  61.           if (this.mSelectedItem)
  62.             this.mSelectedItem.removeAttribute("selected");
  63.           
  64.           this.mSelectedItem = val;
  65.           val.setAttribute("selected", "true");
  66.         ]]></setter>
  67.       </property>
  68.     
  69.       <method name="init">
  70.         <body><![CDATA[
  71.           this.mCount = 0;
  72.           
  73.           this.mConsoleRowBox = document.getAnonymousElementByAttribute(this, "role", "console-rows");
  74.           this.mStrBundle = document.getAnonymousElementByAttribute(this, "role", "string-bundle");
  75.           
  76.           try {
  77.             this.mCService = Components.classes['@mozilla.org/consoleservice;1']
  78.                            .getService(Components.interfaces.nsIConsoleService);
  79.             this.mCService.registerListener(this);
  80.           } catch (ex) {
  81.             this.appendMessage(
  82.               "Unable to display errors - couldn't get Console Service component. " +
  83.               "(Missing @mozilla.org/consoleservice;1)");
  84.             return;
  85.           }          
  86.                     
  87.           this.mMode = this.getAttribute("mode") || "All";
  88.  
  89.           this.appendInitialItems();
  90.         ]]></body>
  91.       </method>
  92.     
  93.       <method name="destroy">
  94.         <body><![CDATA[
  95.           this.mCService.unregisterListener(this);
  96.         ]]></body>
  97.       </method>
  98.     
  99.       <method name="appendInitialItems">
  100.         <body><![CDATA[
  101.           var out = {}; // Throwaway references to support 'out' parameters.
  102.           this.mCService.getMessageArray(out, {});
  103.           var messages = out.value;
  104.       
  105.           // In case getMessageArray returns 0-length array as null
  106.           if (!messages)
  107.             messages = [];
  108.       
  109.           var limit = messages.length - this.limit;
  110.           if (limit < 0) limit = 0;
  111.         
  112.           // Checks if console ever been cleared
  113.           for (var i = messages.length - 1; i >= limit; --i)
  114.             if (!messages[i].message)
  115.               break;
  116.         
  117.           // Populate with messages after latest "clear"
  118.           while (++i < messages.length)
  119.             this.observe(messages[i]);
  120.         ]]></body>
  121.       </method>
  122.  
  123.       <!-- nsIConsoleListener -->
  124.       <method name="observe">
  125.         <parameter name="aConsoleMessage"/>
  126.         <body><![CDATA[
  127.           /* This method may be called in cases where the code
  128.            * called by this method has thrown an exception because
  129.            * some resource ran OUT OF MEMORY (OOM).
  130.            *
  131.            * This method must not throw an exception, because
  132.            * an exception thrown by it could be asynchrounously
  133.            * dispatched back to this method resulting in an
  134.            * asynchronous loop - bug 288544.
  135.            *
  136.            * If you need any try/catch handling for code in this
  137.            * function, please stick it in its own try block inside
  138.            * the main try block. Do *NOT* use the main try block.
  139.            */
  140.           try {
  141.             if (aConsoleMessage instanceof 
  142.                 Components.interfaces.nsIScriptError) {
  143.               // filter chrome urls
  144.               if (!this.showChromeErrors &&
  145.                   /^chrome:/.test(aConsoleMessage.sourceName))
  146.                 return;
  147.  
  148.               this.appendError(aConsoleMessage);
  149.             } else if (aConsoleMessage.message) {
  150.               this.appendMessage(aConsoleMessage.message);
  151.             }
  152.           } catch (e) {
  153.             /* This catch block is for bug 288544,
  154.              * if you want to handle some edge case, please
  155.              * make your own inner try block inside preceding
  156.              * try block. Do *NOT* stick any code in here.
  157.              */
  158.           }
  159.         ]]></body>
  160.       </method>
  161.  
  162.       <method name="appendError">
  163.         <parameter name="aObject"/>
  164.         <body><![CDATA[
  165.           var row = this.createConsoleRow();
  166.           var nsIScriptError = Components.interfaces.nsIScriptError;
  167.           
  168.           // Is this error actually just a non-fatal warning?
  169.           var warning = aObject.flags & nsIScriptError.warningFlag != 0;
  170.   
  171.           var typetext = warning ? "typeWarning" : "typeError";
  172.           row.setAttribute("typetext", this.mStrBundle.getString(typetext));
  173.           row.setAttribute("type", warning ? "warning" : "error");
  174.           row.setAttribute("msg", aObject.errorMessage);
  175.           if (aObject.lineNumber || aObject.sourceName) {
  176.             row.setAttribute("url", aObject.sourceName);
  177.             row.setAttribute("line", aObject.lineNumber);
  178.           } else {
  179.             row.setAttribute("hideSource", "true");
  180.           }
  181.           if (aObject.sourceLine) {
  182.             row.setAttribute("code", aObject.sourceLine.replace("\n", "", "g"));
  183.             if (aObject.columnNumber) {
  184.               row.setAttribute("col", aObject.columnNumber);
  185.               row.setAttribute("errorDots", this.repeatChar(" ", aObject.columnNumber));
  186.               row.setAttribute("errorCaret", " ");
  187.             } else {
  188.               row.setAttribute("hideCaret", "true");
  189.             }
  190.           } else {
  191.             row.setAttribute("hideCode", "true");
  192.           }
  193.           this.appendConsoleRow(row);
  194.         ]]></body>
  195.       </method>
  196.             
  197.       <method name="appendMessage">
  198.         <parameter name="aMessage"/>
  199.         <parameter name="aType"/>
  200.         <body><![CDATA[
  201.           var row = this.createConsoleRow();
  202.           row.setAttribute("type", aType || "message");
  203.           row.setAttribute("msg", aMessage);
  204.           this.appendConsoleRow(row);
  205.         ]]></body>
  206.       </method>
  207.       
  208.       <method name="clear">
  209.         <body><![CDATA[
  210.           this.mCService.logStringMessage(null);
  211.           this.mCount = 0;
  212.           
  213.           var newRows = this.mConsoleRowBox.cloneNode(false);
  214.           this.mConsoleRowBox.parentNode.replaceChild(newRows, this.mConsoleRowBox);
  215.           this.mConsoleRowBox = newRows;
  216.         ]]></body>
  217.       </method>
  218.             
  219.       <method name="copySelectedItem">
  220.         <body><![CDATA[
  221.           if (this.mSelectedItem) try {
  222.             const clipURI = "@mozilla.org/widget/clipboardhelper;1";
  223.             const clipI = Components.interfaces.nsIClipboardHelper;
  224.             var clipboard = Components.classes[clipURI].getService(clipI);
  225.  
  226.             clipboard.copyString(this.mSelectedItem.toString());
  227.           } catch (ex) {
  228.             // Unable to copy anything, die quietly
  229.           }
  230.         ]]></body>
  231.       </method>
  232.                   
  233.       <method name="createConsoleRow">
  234.         <body><![CDATA[
  235.           var row = document.createElement("box");
  236.           row.setAttribute("class", "console-row");
  237.           row._IsConsoleRow = true;
  238.           row._ConsoleBox = this;
  239.           return row;
  240.         ]]></body>
  241.       </method>
  242.             
  243.       <method name="appendConsoleRow">
  244.         <parameter name="aRow"/>
  245.         <body><![CDATA[
  246.           this.mConsoleRowBox.appendChild(aRow);
  247.           if (++this.mCount > this.limit) this.deleteFirst();
  248.         ]]></body>
  249.       </method>
  250.             
  251.       <method name="deleteFirst">
  252.         <body><![CDATA[
  253.           var node = this.mConsoleRowBox.firstChild;
  254.           this.mConsoleRowBox.removeChild(node);
  255.           --this.mCount;
  256.         ]]></body>
  257.       </method>
  258.  
  259.       <method name="repeatChar">
  260.         <parameter name="aChar"/>
  261.         <parameter name="aCol"/>
  262.         <body><![CDATA[
  263.           var str = "";
  264.           if (aCol)
  265.             for (var i = 1; i < aCol; ++i)
  266.               str += aChar;
  267.           
  268.           return str;
  269.         ]]></body>
  270.       </method>
  271.           
  272.       <constructor> this.init(); </constructor>
  273.       <destructor> this.destroy(); </destructor>
  274.     </implementation>
  275.     
  276.     <handlers>
  277.       <handler event="mousedown"><![CDATA[
  278.         if (event.button == 0 || event.button == 2) {
  279.           var target = event.originalTarget;
  280.   
  281.           while (target && !("_IsConsoleRow" in target))
  282.             target = target.parentNode;
  283.  
  284.           if (target)
  285.             this.selectedItem = target;
  286.         }
  287.       ]]></handler>
  288.     </handlers>
  289.   </binding>
  290.  
  291.   <binding id="error" extends="xul:box">
  292.     <content>
  293.       <xul:box class="console-row-internal-box" flex="1">
  294.         <xul:box class="console-row-icon" align="center" xbl:inherits="selected">
  295.           <xul:image class="console-icon" xbl:inherits="src,type"/>
  296.         </xul:box>
  297.         <xul:vbox class="console-row-content" xbl:inherits="selected" flex="1">
  298.           <xul:box class="console-row-msg" align="start">
  299.             <xul:label class="label" xbl:inherits="value=typetext"/>
  300.             <xul:description class="console-error-msg" xbl:inherits="xbl:text=msg" flex="1"/>
  301.           </xul:box>
  302.           <xul:box class="console-row-file" xbl:inherits="hidden=hideSource">
  303.             <xul:label class="label" value="&errFile.label;"/>
  304.             <xul:box class="console-error-source" xbl:inherits="url,line"/>
  305.             <spacer flex="1"/>
  306.             <xul:label class="label" value="&errLine.label;"/>
  307.             <xul:label class="label" xbl:inherits="value=line" flex="1"/>
  308.           </xul:box>
  309.           <xul:vbox class="console-row-code" xbl:inherits="selected,hidden=hideCode">
  310.             <xul:label class="monospace console-code" xbl:inherits="value=code" crop="end"/>
  311.             <xul:box xbl:inherits="hidden=hideCaret">
  312.               <xul:label class="monospace console-dots" xbl:inherits="value=errorDots"/>
  313.               <xul:label class="monospace console-caret" xbl:inherits="value=errorCaret"/>
  314.               <xul:spacer flex="1"/>
  315.             </xul:box>
  316.           </xul:vbox>
  317.         </xul:vbox>
  318.       </xul:box>
  319.     </content>
  320.  
  321.     <implementation>
  322.       
  323.       <method name="toString">
  324.         <body><![CDATA[
  325.           var msg = this.getAttribute("typetext") + " " + this.getAttribute("msg");
  326.           
  327.           var strBundle = this._ConsoleBox.mStrBundle;
  328.           
  329.           if (this.hasAttribute("line") && this.hasAttribute("url")) {
  330.             msg += "\n" + strBundle.getFormattedString("errFile", 
  331.                                         [this.getAttribute("url")]) + "\n";
  332.             if (this.hasAttribute("col")) {
  333.               msg += strBundle.getFormattedString("errLineCol",
  334.                          [this.getAttribute("line"), this.getAttribute("col")]);
  335.             } else
  336.               msg += strBundle.getFormattedString("errLine", [this.getAttribute("line")]);
  337.           }
  338.           
  339.           if (this.hasAttribute("code"))
  340.             msg += "\n" + strBundle.getString("errCode") + "\n" + this.getAttribute("code");
  341.           
  342.           return msg;
  343.         ]]></body>
  344.       </method>
  345.       
  346.     </implementation>
  347.     
  348.   </binding>
  349.   
  350.   <binding id="message" extends="xul:box">
  351.     <content>
  352.       <xul:box class="console-internal-box" flex="1">
  353.         <xul:box class="console-row-icon" align="center">
  354.           <xul:image class="console-icon" xbl:inherits="src,type"/>
  355.         </xul:box>
  356.         <xul:vbox class="console-row-content" xbl:inherits="selected" flex="1">
  357.           <xul:vbox class="console-row-msg" flex="1">
  358.             <xul:description class="console-msg-text" xbl:inherits="xbl:text=msg"/>
  359.           </xul:vbox>
  360.         </xul:vbox>
  361.       </xul:box>
  362.     </content>
  363.  
  364.     <implementation>
  365.       <method name="toString">
  366.         <body><![CDATA[
  367.           return this.getAttribute("msg");
  368.         ]]></body>
  369.       </method>
  370.     </implementation>
  371.   </binding>
  372.  
  373.   <binding id="console-error-source" extends="xul:box">
  374.     <content>
  375.       <xul:label class="text-link" xbl:inherits="value=url" crop="right"/>
  376.     </content>
  377.  
  378.     <handlers>
  379.       <handler event="click" button="0"><![CDATA[
  380.           var url = this.getAttribute("url");
  381.           var line = getAttribute("line");  
  382.           window.openDialog(
  383.             "chrome://navigator/content/viewSource.xul", "_blank", 
  384.             "all,dialog=no", url, null, null, line);
  385.       ]]></handler>
  386.     </handlers>
  387.   </binding>
  388.  
  389. </bindings>
  390.  
  391.